package com.ohs.ohsoa.system.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.ohs.ohsoa.system.dto.ScheduleTypeDto;
import com.ohs.ohsoa.system.service.ScheduleTypeService;
import com.ohs.ohsoa.system.vo.ScheduleTypeVo;
import com.ohs.ohsoa.utils.auth.UserLoginToken;
import com.ohs.ohsoa.utils.bean.requestBean.PageParam;
import com.ohs.ohsoa.utils.bean.responseBean.ResultBean;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 日程类别Controller
 *
 * @author zhangjy
 *
 */

@Api(value = "日程类别管理", tags = "日程类别管理")
@RestController
@RequestMapping("/scheduletype")
public class ScheduleTypeController {

    @Resource
    private ScheduleTypeService scheduleTypeService;

    /**
     * 获取日程类别列表信息
     *
     * @param pageParam 检索用参数
     * @return 日程类别列表信息
     *
     */
    @UserLoginToken
    @PostMapping(value = "/select/list")
    @ApiOperation(httpMethod = "POST", value = "获取日程类别列表信息")
    public ResultBean<PageInfo<ScheduleTypeVo>> scheduleTypeSelectList(@RequestBody PageParam<ScheduleTypeDto> pageParam) {
        List<ScheduleTypeVo> res = scheduleTypeService.scheduleTypeSelectList(pageParam);
        return ResultBean.success(new PageInfo<>(res));
    }

    /**
     * 根据id获取日程类别详细信息
     *
     * @param scheduleTypeDto 日程类别详细信息数据
     * @return 日程列别详细信息
     *
     * stId必传
     */
    @UserLoginToken
    @PostMapping(value = "/select")
    @ApiOperation(httpMethod = "POST", value = "根据id获取日程类别详细信息")
    public ResultBean<ScheduleTypeVo> scheduleTypeSelect(@RequestBody ScheduleTypeDto scheduleTypeDto) {
        return ResultBean.success(scheduleTypeService.scheduleTypeSelect(scheduleTypeDto));
    }

    /**
     * 新增日程类别
     *
     * @param scheduleTypeDto 日程类别数据
     * @return 新增结果
     */
    @UserLoginToken
    @PostMapping(value = "/insert")
    @ApiOperation(httpMethod = "POST", value = "新增日程类别")
    public ResultBean<Boolean> scheduleTypeInsert(@RequestBody @Valid ScheduleTypeDto scheduleTypeDto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultBean.success(scheduleTypeService.scheduleTypeInsert(scheduleTypeDto));
    }


    /**
     * 删除日程类别
     *
     * @param scheduleTypeDto 日程类别数据
     * @return 删除结果
     */
    @UserLoginToken
    @DeleteMapping(value = "/delete")
    @ApiOperation(httpMethod = "DELETE", value = "删除日程类别")
    public ResultBean<Boolean> scheduleTypeDelete(@RequestBody ScheduleTypeDto scheduleTypeDto) {
        return ResultBean.success(scheduleTypeService.scheduleTypeDelete(scheduleTypeDto));
    }




    /**
     * 修改日程类别
     *
     * @param scheduleTypeDto 日程类别信息数据
     * @return 修改结果
     */
    @UserLoginToken
    @PutMapping(value = "/update")
    @ApiOperation(httpMethod = "PUT", value = "修改日程类别")
    public ResultBean<Boolean> scheduleTypeUpdate(@RequestBody @Valid ScheduleTypeDto scheduleTypeDto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultBean.success(scheduleTypeService.scheduleTypeUpdate(scheduleTypeDto));
    }
}
